package com.fdb.efp.loan.service.impl;

import java.util.List;
import java.util.Objects;

import com.fdb.efp.loan.service.domain.BdAccLedgerTemp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.fdb.efp.loan.service.dao.BdAccLedgerTempDao;
import com.fdb.efp.loan.service.facade.BdAccLedgerTempService;
import com.fdb.efp.loan.service.vo.BdAccLedgerTempVO;

/**
 * <p>
 * ServiceImpl: 百度并账临时表
 * <p>
 * 
 * @author ligm
 * @date 2019-03-07
 */
@Service("bdAccLedgerTempService")
public class BdAccLedgerTempServiceImpl implements BdAccLedgerTempService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(BdAccLedgerTempServiceImpl.class);

	@Autowired
	private BdAccLedgerTempDao bdAccLedgerTempDao;

	/**
	 * 新增操作
	 */
	public int insertBdAccLedgerTemp(BdAccLedgerTempVO inBdAccLedgerTempVo) {
		logger.debug("当前新增数据为:" + inBdAccLedgerTempVo.toString());
		int num = 0;
		try {
			BdAccLedgerTemp bdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, bdAccLedgerTemp);
			num = bdAccLedgerTempDao.insertBdAccLedgerTemp(bdAccLedgerTemp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:" + num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(BdAccLedgerTempVO inBdAccLedgerTempVo) {
		logger.debug("当前删除数据条件为:" + inBdAccLedgerTempVo);
		int num = 0;
		try {
			BdAccLedgerTemp bdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, bdAccLedgerTemp);
			num = bdAccLedgerTempDao.deleteByPk(bdAccLedgerTemp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLedgerTempVo + "删除的数据条数为" + num);
		return num;
	}

	/**
	 * 更新操作
	 */
	public int updateByPk(BdAccLedgerTempVO inBdAccLedgerTempVo) {
		logger.debug("当前修改数据为:" + inBdAccLedgerTempVo.toString());
		int num = 0;
		try {
			BdAccLedgerTemp bdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, bdAccLedgerTemp);
			num = bdAccLedgerTempDao.updateByPk(bdAccLedgerTemp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:" + inBdAccLedgerTempVo + "修改的数据条数为" + num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public BdAccLedgerTempVO queryByPk(BdAccLedgerTempVO inBdAccLedgerTempVo) {

		logger.debug("当前查询参数信息为:" + inBdAccLedgerTempVo);
		try {
			BdAccLedgerTemp queryBdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, queryBdAccLedgerTemp);
			BdAccLedgerTemp queryRslBdAccLedgerTemp = bdAccLedgerTempDao.queryByPk(queryBdAccLedgerTemp);
			if (Objects.nonNull(queryRslBdAccLedgerTemp)) {
				BdAccLedgerTempVO outBdAccLedgerTempVo = beanCopy(queryRslBdAccLedgerTemp, new BdAccLedgerTempVO());
				logger.debug("当前查询结果为:" + outBdAccLedgerTempVo.toString());
				return outBdAccLedgerTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询操作
	 */
	public BdAccLedgerTempVO queryByPkMYD(BdAccLedgerTempVO inBdAccLedgerTempVo) {

		logger.debug("当前查询参数信息为:" + inBdAccLedgerTempVo);
		try {
			BdAccLedgerTemp queryBdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, queryBdAccLedgerTemp);
			BdAccLedgerTemp queryRslBdAccLedgerTemp = bdAccLedgerTempDao.queryByPkMYD(queryBdAccLedgerTemp);
			if (Objects.nonNull(queryRslBdAccLedgerTemp)) {
				BdAccLedgerTempVO outBdAccLedgerTempVo = beanCopy(queryRslBdAccLedgerTemp, new BdAccLedgerTempVO());
				logger.debug("当前查询结果为:" + outBdAccLedgerTempVo.toString());
				return outBdAccLedgerTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询操作
	 */
	public BdAccLedgerTempVO queryByPkZXD(BdAccLedgerTempVO inBdAccLedgerTempVo) {
		logger.debug("当前查询参数信息为:" + inBdAccLedgerTempVo);
		try {
			BdAccLedgerTemp queryBdAccLedgerTemp = new BdAccLedgerTemp();
			beanCopy(inBdAccLedgerTempVo, queryBdAccLedgerTemp);
			BdAccLedgerTemp queryRslBdAccLedgerTemp = bdAccLedgerTempDao.queryByPkZXD(queryBdAccLedgerTemp);
			if (Objects.nonNull(queryRslBdAccLedgerTemp)) {
				BdAccLedgerTempVO outBdAccLedgerTempVo = beanCopy(queryRslBdAccLedgerTemp, new BdAccLedgerTempVO());
				logger.debug("当前查询结果为:" + outBdAccLedgerTempVo.toString());
				return outBdAccLedgerTempVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerTempVO> queryAllOwner(BdAccLedgerTempVO bdAccLedgerTempVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<BdAccLedgerTempVO> list = null;
		try {
			List<BdAccLedgerTemp> bdAccLedgerTemps = bdAccLedgerTempDao.queryAllOwnerByPage(bdAccLedgerTempVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:" + bdAccLedgerTemps.size());
			pageSet(bdAccLedgerTemps, bdAccLedgerTempVo);
			list = (List<BdAccLedgerTempVO>) beansCopy(bdAccLedgerTemps, BdAccLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerTempVO> queryAllCurrOrg(BdAccLedgerTempVO bdAccLedgerTempVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<BdAccLedgerTemp> bdAccLedgerTemps = bdAccLedgerTempDao.queryAllCurrOrgByPage(bdAccLedgerTempVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:" + bdAccLedgerTemps.size());
		List<BdAccLedgerTempVO> list = null;
		try {
			pageSet(bdAccLedgerTemps, bdAccLedgerTempVo);
			list = (List<BdAccLedgerTempVO>) beansCopy(bdAccLedgerTemps, BdAccLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}

	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<BdAccLedgerTempVO> queryAllCurrDownOrg(BdAccLedgerTempVO bdAccLedgerTempVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<BdAccLedgerTemp> bdAccLedgerTemps = bdAccLedgerTempDao.queryAllCurrDownOrgByPage(bdAccLedgerTempVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:" + bdAccLedgerTemps.size());
		List<BdAccLedgerTempVO> list = null;
		try {
			pageSet(bdAccLedgerTemps, bdAccLedgerTempVo);
			list = (List<BdAccLedgerTempVO>) beansCopy(bdAccLedgerTemps, BdAccLedgerTempVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
}
